Skip to content

fix(id/web): validate /api/images payload shape before rendering in image browser - #7815

Merged
dezren39 merged 1 commit into
mainfrom
queue/13991-7812-images-shape-validation
Nov 8, 2026
Merged

dezren39 merged 1 commit into
mainfrom
queue/13991-7812-images-shape-validation

Conversation

@dezren39

@dezren39 dezren39 commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

Fixes #7812

Problem

fetchImages() in pkgs/id/web/src/image-browser.ts bare-cast the /api/images response as ImageEntry[]. A wrong-shape 200 (deploy skew / future contract change) then:

  • wiped the grid before any validation,
  • dumped a raw engine TypeError into the dialog via the catch handler, or
  • rendered bogus undefined cards whose Insert created an image node with undefined src/alt.

Fix

  • parseImageEntries() validates the payload against the server contract (pkgs/id/src/web/routes.rs images_list_handler: a bare array of {hash, name, url: string, size: number}) inside fetchImages(), before any grid mutation — all-or-nothing: one malformed element rejects the whole payload with a clean unexpected response from /api/images error.
  • The catch handler now renders only err.message, never raw exception text.

Tests (oracle: the routes.rs ImageEntry contract)

  • New regression cases in image-browser.test.ts: null body, non-array object body, string body, null element, wrong-typed field, missing field, and a mixed valid+invalid array — each asserts no cards, Insert stays disabled, and no TypeError/undefined text. All 7 fail pre-fix, pass post-fix.
  • image-browser.test.ts: 20/20 pass.
  • Full web suite: 676 pass, 9 skipped, 1 failure in search-panel.test.ts (accessibility role test) — verified pre-existing on clean main db27c4ed3b with these changes stashed.
  • tsc --noEmit clean.

Queue task 13991 (repo-health-code-pilot, lane code-p, direct).


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…mage browser

fetchImages() bare-cast the /api/images response as ImageEntry[], so a
wrong-shape 200 wiped the grid, leaked a raw TypeError into the dialog,
or rendered bogus cards whose Insert created src-less image nodes.

Validate the payload against the routes.rs ImageEntry contract
(bare array of {hash, name, url: string, size: number}) before any
grid mutation, all-or-nothing, and surface only the clean error
message. Regression tests cover null/non-array/string bodies, null
elements, wrong-typed and missing fields, and mixed valid+invalid
arrays; they fail pre-fix.

Fixes #7812
@dezren39
dezren39 requested a review from a team as a code owner November 8, 2026 21:30
@coderabbitai

coderabbitai Bot commented Nov 8, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 21 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 135cb11f-8101-4c5e-a9c6-f4725873f01b
Commits

Reviewing files that changed from the base of the PR and between db27c4e and 41d0bed.

Files selected for processing: 2

  • pkgs/id/web/src/image-browser.test.ts
  • pkgs/id/web/src/image-browser.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-08T21:32:22.965526Z 41d0bed PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant